package com.zzptc.shop.servlet;

import com.zzptc.shop.dao.UserDao;
import com.zzptc.shop.db.GoodIDB;
import com.zzptc.shop.db.IDB;
import com.zzptc.shop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

@WebServlet(name = "RegServlet")
public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf8");
        response.setCharacterEncoding("utf8");
        PrintWriter pw=response.getWriter();
        //获取表单
        String name=request.getParameter("userName");
        String pass=request.getParameter("passWord");
        Users users=new Users();
        users.setEu_user_id(name);
        users.setEu_password(pass);
        boolean i=false;
        UserDao userDao=new UserDao();
        try {
           i=userDao.insert(users);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(i){
            pw.print("成功");
        }else {
            pw.print("失败");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
